<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of myvideo
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Myvideo extends MY_Controller {

    //put your code here


    function myvideo() {
        parent :: __construct();
        $this->load->model('pickup_model');
        $this->load->model('location_model');
        $this->load->model('member_model');
        $this->load->model('management_model');
        $this->load->model('listing_model');
        $this->load->model('terms_model');
    }

    function video($listing_id) {
        $id = intval($this->session->userdata('mem_id'));
        $data['member']['info'] = $this->member_model->get_member($id);
        $data['listing']['info'] = $this->listing_model->get_listing($listing_id);
        $data['terms']['listing-video'] = $this->terms_model->get_terms('listing-video', $listing_id);

        $this->template->title('Welcome', 'carz.com')
                ->set_partial('header', 'header/header')
                ->set_partial('footer', 'footer/footer')
                ->set_partial('customer_care', 'sidebar/customer_care')
                ->set_partial('social_share', 'sidebar/social_share')
                ->set_partial('search_reviews', 'sidebar/search_reviews')
                ->set_partial('recent_news', 'sidebar/recent_news')
                ->set_partial('recent_reviews', 'sidebar/recent_reviews')
                ->build('pages/member/video', $data);
    }

//--Insert Photo //--
    function insert($listing_id=0) {
        $this->form_validation->set_rules('videourl', 'Video Url', 'trim|required|prep_url');
        if ($this->form_validation->run() == TRUE) {
            $insert_data = array(
                'listing_id' => intval($listing_id),
                'term' => 'listing-video',
                'description' => trim($this->input->post('videourl'))
            );
            $this->db->insert('terms', $insert_data);
        } else {
            $this->session->set_flashdata('message', $this->upload->display_errors('<p class="error">', '</p>'));
        }
        redirect('member/myvideo/video/' . $listing_id);
    }
    
//--Delete Video ---//
    function delete($id,$listing_id){
        if($id){
            $term['data'] = $this->terms_model->get_term($id);
            $sql = "delete from terms where id = $id";
            $query = $this->db->query($sql);
        }
        redirect('member/myvideo/video/' . $listing_id);
    }

}

?>
